package com.ibeetl.cms.web;

import com.ibeetl.cms.entity.XxdStatistics;
import com.ibeetl.cms.service.XxdStatisticsService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class HomeController {

    private final Log log = LogFactory.getLog(this.getClass());
    private static final String MODEL = "/admin/home";
    @Autowired
    private XxdStatisticsService xxdStatisticsService;

    @GetMapping(MODEL + "/index.do")
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("/admin/home/home.html");

        List<XxdStatistics> list = xxdStatisticsService.queryByCondition();
        if(list != null && list.size() != 0){
            XxdStatistics statistics = list.get(0);
            view.addObject("statistics", statistics);
        }else{
            view.addObject("statistics", new XxdStatistics());

        }
        return view;
    }


}
